home *** CD-ROM | disk | FTP | other *** search
/ NeXTSTEP 3.3 (Developer)…68k, x86, SPARC, PA-RISC] / NeXTSTEP 3.3 Dev Intel.iso / NextDeveloper / Headers / architecture / hppa / asm_help.h < prev    next >
Text File  |  1994-06-08  |  6KB  |  197 lines

  1. /* Copyright (c) 1993 NeXT Computer, Inc.  All rights reserved.
  2.  *
  3.  *    File:    architecture/hppa/asm_help.h
  4.  *    Author:    Joshua Doenias, NeXT Computer, Inc.
  5.  *
  6.  *    This header file defines macros useful when writing assembly code
  7.  *    for the HP PA-RISC family processors.
  8.  *
  9.  * HISTORY
  10.  * 9-Aug-93  Joshua Doenias (josh@next.com)
  11.  *    Created.
  12.  */
  13.  
  14. #ifndef    _ARCH_HPPA_ASM_HELP_H_
  15. #define    _ARCH_HPPA_ASM_HELP_H_
  16.  
  17. #ifdef    __ASSEMBLER__
  18.  
  19. /*  Interesting register aliases */
  20.  
  21. #define zero    %r0    // architecturally defined to be 0
  22. #define rp    %r2    // return pointer
  23. #define fp    %r4    // frame pointer
  24. #define arg0    %r26    // general args
  25. #define arg1    %r25
  26. #define arg2    %r24
  27. #define arg3    %r23
  28. #define ret0    %r28    // return values
  29. #define ret1    %r29
  30. #define sp    %r30    // stack pointer
  31.  
  32. #define fdarg0    %fr5    // double arg 0
  33. #define fdarg1    %fr7    // double arg 1
  34. #define fsarg0    %fr4    // float arg 0
  35. #define fsarg1    %fr5    // float arg 1
  36. #define fsarg2  %fr6    // float arg 2
  37. #define fsarg3  %fr7    // float arg 3
  38. #define fret    %fr4    // return val
  39.  
  40. /* 
  41.  * This is what the hppa stack looks like at the time the function is called.
  42.  * Note that this is set up BY THE CALLER.  The called function only has
  43.  * to set up a frame if it is going to call other functions, or use local
  44.  * space.
  45.  *
  46.  *                            High addresses
  47.  * 
  48.  * SP  ----> callee allocates locals here   ( old fp saved here if needed )
  49.  *          +----------------------------+
  50.  * SP-4     |   16 bytes (unused in NS)  |
  51.  *          +----------------------------+
  52.  * SP-20    |       old RP home          |
  53.  *          +----------------------------+
  54.  * SP-24    |     12 byte frame area     |
  55.  *          |    (unused in NEXTSTEP)    |
  56.  *          +----------------------------+
  57.  * SP-36    |        arg 0 home          |
  58.  *          +----------------------------+
  59.  * SP-40    |        arg 1 home          |
  60.  *          +----------------------------+
  61.  *          |        arg 2 home          |
  62.  *          +----------------------------+
  63.  *          |        arg 3 home area     |
  64.  *          +----------------------------+
  65.  * SP-52    | additional args on stack.. |        Low addresses
  66.  *
  67.  *  If a procedure will call another proc, it needs to allocate the above
  68.  *  48 bytes on its stack.  Additional space is allocated for local vars.
  69.  *  The whole shebang is rounded up to a multiple of 64 bytes.
  70.  */
  71.  
  72. /* ARG(n)  offset to argument area.  These are 0 based -- ARG(0) is 
  73.  * the first argument.
  74.  * Note that at the time the procedure is called, only arg words 4 and >
  75.  * are on the stack.  0-3 are in registers, although a homing area is 
  76.  * available for them.
  77.  * In a leaf procedure with no locals, this macro can be used as a stack
  78.  * offset.  In a nested procedure or a leaf with locals declared, this 
  79.  * macro is actually a frame offset.
  80.  */
  81. #define ARG(n)  (((n)*4) - 36)
  82.  
  83. /* LOCAL_VAR(n)  frame offset to local variable area.  These are 0 based --
  84.  * LOCAL_VAR(0) is the first local word.
  85.  * This is an index into the local argument words.  If the function is putting
  86.  * anything other than words into local storage, it must account for them
  87.  * itself.
  88.  * Also, this macro is only valid if the function has been declared using
  89.  * either LEAF() or NESTED() with a local variable size greater than 0.
  90.  *
  91.  * It can be used as follows:
  92.  *   ldw     LOCAL_VAR(0)(0,fp), ret0    ; loads first local in return val
  93.  *   stw      arg0, LOCAL_VAR(0)(0,fp)    ; stores first arg in first local
  94.  */
  95.  
  96. #define LOCAL_VAR(n)  (((n)+1)*4)
  97.  
  98.  
  99.  
  100.  
  101. /* Macros for building stack frame */
  102.  
  103.  
  104. /* Stack is always aligned to 64 bytes */
  105. #define STACK_INCR    64
  106. #define ROUND_TO_STACK(len)            \
  107.     (((len) + STACK_INCR - 1) & ~(STACK_INCR-1))
  108.  
  109. #define NESTED_FUNCTION_PROLOGUE(localvarsize)             \
  110.     stw    rp,-20(0,%r30)                  @\
  111.     .set    __framesize,ROUND_TO_STACK(localvarsize+52)    @\
  112.     .set     __nested_function,1                @\
  113.     copy    fp,%r1                        @\
  114.     copy    sp,fp                        @\
  115.     stwm    %r1,__framesize(0,sp)
  116.  
  117. #define LEAF_FUNCTION_PROLOGUE(localvarsize)            \
  118.     .set  __nested_function,0                @\
  119.     .if localvarsize                    @\
  120.       .set __framesize,ROUND_TO_STACK(localvarsize+4)    @\
  121.       copy  fp,%r1                        @\
  122.       copy    sp,fp                        @\
  123.       stwm    %r1,__framesize(0,sp)                @\
  124.     .else                             @\
  125.       .set __framesize,0                    @\
  126.     .endif
  127.  
  128. #define FUNCTION_EPILOGUE                    \
  129.     .if __nested_function                    @\
  130.        ldw -20(0,fp),rp                    @\
  131.     .endif                            @\
  132.     .if __framesize                        @\
  133.       bv 0(rp)                        @\
  134.       ldwm -__framesize(0,sp),fp                @\
  135.     .else                            @\
  136.       bv,n 0(rp)                        @\
  137.     .endif        
  138.       
  139. /*
  140.  * LEAF - declare global leaf procedure
  141.  */
  142. #define LEAF(name,localvarsize)                    \
  143.     .align 2                        @\
  144.     .globl name                        @\
  145. name:                                @\
  146.     LEAF_FUNCTION_PROLOGUE(localvarsize)
  147.     
  148. /*
  149.  * P_LEAF - declare private leaf procedure
  150.  */
  151. #define P_LEAF(name,localvarsize)                \
  152.     .align 2                        @\
  153. name:                                @\
  154.     LEAF_FUNCTION_PROLOGUE(localvarsize)
  155.  
  156.  
  157. /*
  158.  * NESTED -- declare procedure that invokes other procedures
  159.  */
  160. #define NESTED(name,localvarsize)                \
  161.     .align 2                        @\
  162.     .globl name                        @\
  163. name:                                @\
  164.     NESTED_FUNCTION_PROLOGUE(localvarsize)
  165.  
  166. /*
  167.  * P_NESTED -- declare private procedure that invokes other procedures
  168.  */
  169. #define P_NESTED(name,localvarsize)                \
  170.     .align 2                        @\
  171. name:                                @\
  172.     NESTED_FUNCTION_PROLOGUE(localvarsize)
  173.  
  174. /*
  175.  * END -- mark end of procedure
  176.  */
  177. #define END(name)                        \
  178.      FUNCTION_EPILOGUE
  179.  
  180. #define    X_NESTED(name, value)                \
  181.     .globl    name                    @\
  182.     .set    name,value
  183.  
  184.  
  185. /*
  186.  * LONG_CALL -- long branch to function
  187.  */
  188. #define LONG_CALL(name)                        \
  189.      ldil  L`##name,%r1                        @\
  190.      ble   R`##name(%sr4,%r1)                    @\
  191.      copy  %r31,rp
  192.  
  193. #endif  __ASSEMBLER__
  194. #endif    _ARCH_HPPA_ASM_HELP_H_
  195.  
  196.  
  197.